﻿namespace Bango.WindowsPhone7.SDK
{
	public class BangoProfile
	{
		public System.String ApplicationChannel { get; set; }
		public System.String ApplicationId { get; set; }
		public System.String ApplicationType { get; set; }
		public System.String ApplicationVersion { get; set; }
		public System.String ConnectionType { get; set; }
		public System.String CountryISO { get; set; }
		public System.String DeviceBrand { get; set; }
		public System.Boolean DeviceIsMobile { get; set; }
		public System.String DeviceMake { get; set; }
		public System.String DeviceModel { get; set; }
		public System.String DeviceVersion { get; set; }
		public System.Boolean IsRoaming { get; set; }
		public System.Double LocationAccuracy { get; set; }
		public System.String LocationCountryISO { get; set; }
		public System.String LocationRegion { get; set; }
		public System.String LocationSource { get; set; }
		public System.String LocationTown { get; set; }
		public System.Double LocationX { get; set; }
		public System.Double LocationY { get; set; }
		public System.Double LocationZ { get; set; }
		public System.String OperatingSystem { get; set; }
		public System.String OperatingSystemVersion { get; set; }
		public System.String OperatingSystemVersionName { get; set; }
		public System.String OperatorCode { get; set; }
		public System.String OperatorConnectionType { get; set; }
		public System.String OperatorName { get; set; }
		public System.Boolean Posted { get; set; }
		public System.Int32 SDKType { get; set; }
		public System.String SDKVersion { get; set; }
		public System.Int32 SessionRestartTime { get; set; }
		public System.String UserId { get; set; }

		public System.Int32 ProfileId { get; set; }

		public System.Collections.Generic.List<BangoEvent> Events { get; set; }

		public BangoProfile()
		{
			Events = new System.Collections.Generic.List<BangoEvent>();
		}

		internal BangoProfile(System.Int32 profileId, System.Int32 sdkType, System.String sdkVersion, System.String applicationId, System.String applicationType, System.String applicationChannel, System.String applicationVersion, System.String userId, System.Int32 connectionType, System.Int32 sessionRestartTime, System.Boolean isRoaming, System.String locationSource, System.Double locationAltitude, System.Double locationLatitude, System.Double locationLongitude, System.Double locationAccuracy, System.String operatorCode, System.String operatorName, System.String operatorCountryIso, System.String brand, System.String device, System.String model, System.String product, System.String version, System.String buildId, System.Int32 operatorConnectionType, System.String simOperator)
			: this()
		{
			ProfileId = profileId;
			SDKType = sdkType;
			SDKVersion = sdkVersion;
			ApplicationId = applicationId;
			ApplicationType = applicationType;
			ApplicationChannel = applicationChannel;
			ApplicationVersion = applicationVersion;
			UserId = userId;
			ConnectionType = BangoStatic.ConnectionType(connectionType);
			IsRoaming = isRoaming;
			LocationSource = locationSource;
			LocationZ = locationAltitude;
			LocationY = locationLatitude;
			LocationX = locationLongitude;
			LocationAccuracy = locationAccuracy;
			SessionRestartTime = sessionRestartTime;
			OperatorCode = operatorCode;
			OperatorConnectionType = BangoStatic.OperatorConnectionType(operatorConnectionType);
			OperatorName = operatorName;
			OperatingSystemVersion = version;
			DeviceMake = device;
			DeviceModel = model;
			DeviceVersion = buildId;
			//COMMENT : This is currently unavailable in WP7 - Code has been left in should it become available.
			//OperatorCountryIso = operatorCountryIso;
			//Brand = brand;
			//Device = device;
			//Model = model;
			//Product = product;
			//Version = version;
			//BuildId = buildId;
			//OperatorConnectionType = operatorConnectionType;
			//SimOperator = simOperator;
		}

		internal BangoProfile GetProfileForPost()
		{

			System.Collections.Generic.List<BangoEventParameter> eventParameters;
			BangoProfile returnValue;

			returnValue = new BangoProfile(this.ProfileId, this.SDKType, this.SDKVersion, this.ApplicationId, this.ApplicationType, this.ApplicationChannel, this.ApplicationVersion, this.UserId, 0, this.SessionRestartTime, this.IsRoaming, this.LocationSource, this.LocationZ, this.LocationY, this.LocationX, this.LocationAccuracy, this.OperatorCode, this.OperatorName, System.String.Empty, System.String.Empty, this.DeviceMake, this.DeviceModel, System.String.Empty, this.OperatingSystemVersion, this.DeviceVersion, 0, System.String.Empty);
			returnValue.ConnectionType = this.ConnectionType;
			returnValue.OperatorConnectionType = this.OperatorConnectionType;
			foreach (BangoEvent ev in this.Events)
			{
				if (!ev.Posted)
				{
					if (ev.EventParameters == null)
					{
						eventParameters = null;
					}
					else
					{
						eventParameters = new System.Collections.Generic.List<BangoEventParameter>();
						foreach (BangoEventParameter parameter in ev.EventParameters)
						{
							eventParameters.Add(new BangoEventParameter(parameter.Name, parameter.Value));
						}
					}
					returnValue.Events.Add(new BangoEvent(ev.ProfileId, ev.EventId, 0, 0, ev.ErrorLevel, ev.EventName, ev.EventDetail, ev.EventValue, ev.ErrorId, System.Convert.ToDateTime(ev.EventTime), System.Convert.ToDateTime(ev.EventLocalTime), eventParameters));
					returnValue.Events[returnValue.Events.Count - 1].ConnectionType = ev.ConnectionType;
					returnValue.Events[returnValue.Events.Count - 1].OperatorConnectionType = ev.OperatorConnectionType;
				}
			}
			return returnValue;
		}

		//12-10-11 JP Returns a copy of the profile without the events, for saving to the profile store
		internal BangoProfile GetProfileForSave()
		{
			BangoProfile returnValue;
			returnValue = new BangoProfile(this.ProfileId, this.SDKType, this.SDKVersion, this.ApplicationId, this.ApplicationType, this.ApplicationChannel, this.ApplicationVersion, this.UserId, 0, this.SessionRestartTime, this.IsRoaming, this.LocationSource, this.LocationZ, this.LocationY, this.LocationX, this.LocationAccuracy, this.OperatorCode, this.OperatorName, System.String.Empty, System.String.Empty, this.DeviceMake, this.DeviceModel, System.String.Empty, this.OperatingSystemVersion, this.DeviceVersion, 0, System.String.Empty);
			returnValue.ConnectionType = this.ConnectionType;
			returnValue.OperatorConnectionType = this.OperatorConnectionType;
			return returnValue;
		}

	}
}
